<template>
  <a-modal v-model:visible="modal" title="物料商品列表" width="80%" >
    <s-table
      ref="table"
      table-id="SYS_WAREHOUSE_TABLE"
      :columns="columns1"
      :data="loadData"
      bordered
      :row-key="(record) => record.id"
    >
    <template #bodyCell="{ column, record,index }">
        <template v-if="column?.dataIndex === 'action'">
          <a-space>
            <a-button type="primary" size="small" @click="handleConfirm(record,index)">确认</a-button>
          </a-space>
        </template>
      </template>
    </s-table>
    </a-modal>
  
  </template>
  
  <script setup>
  import materialapi  from '@/api/wms/material/materialapi'
   import warehouseapi  from '@/api/wms/warehouse/warehouseapi'
  
  const columns1 = [
      {title: '物料名称',dataIndex: 'productname', key:'materialname'},
      { title: '当前库存', dataIndex: 'inventoryqty', key:'materialtype'},
      { title: '规格', dataIndex: 'specification', key:'specification'},
      {title: '单价', dataIndex: 'price', key:'unit' },
      { title: '操作', dataIndex: 'action', align: 'center', width: '200px'}
    ]


    const loadData = (parameter) => {
     return warehouseapi.getInventoryWarring({parameter}).then(res=>{
        return res
      })
    }
  const modal = ref(false)
  const rowindex=ref(null) //接收父组件传递过来的行
    //打开对话框
    const openmodal=(index)=>{
      rowindex.value=index//获取从父组件传递过来的行
      modal.value=true//打开弹框
    }
  //声明自定义组件
  const emit = defineEmits(['confirm']);
  
   const handleConfirm =(record)=>{
    emit('confirm', record,rowindex.value); // 向父组件传递选中数据
    modal.value = false;  //关闭弹窗
  }
  
  
    defineExpose({
      openmodal
    })
  </script>